package designpattern.singleton;

public class AppMain {

	public static void main(String[] args) {
		Thread thread1 = new Thread(new A());
		thread1.start();

		Thread thread2 = new Thread(new B());
		thread2.start();
	}
}
class A implements Runnable{
	public String testname(){
		SingletonClass class1 = SingletonClass.getSingletonClass();
		try {
			if (class1.sayHello()==null)
				return "lock";
			else 
				return class1.sayHello();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "lock";
	}
	@Override
	public void run() {
		int i = 0;
		while (0<100) {

			System.out.print("A" + i + testname());
			try {
				Thread.sleep(1000);
				i++;
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

}
class B implements Runnable{
	public String testname(){
		SingletonClass class1 = SingletonClass.getSingletonClass();
		try {
			if (class1.sayHello()==null)
				return "lock";
			else 
				return class1.sayHello();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "lock";
	}
	@Override
	public void run() {
		int i = 0;
		while (0<100) {
			testname();
			System.out.print("B" + i + testname());
			try {
				Thread.sleep(1000);
				i++;
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

}